package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.suanhua.*;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/*
 * 算话早期风险识别-定制变量
 *
 * @author:szw
 * */

public class SuanHuaRiskIdentRecordParse extends ParseBase {
    Text key = new Text();
    Text val = new Text();

    /**
     * @param context
     * @param model
     * @param successful
     * @return
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        SuanhuaRiskIdentCustomizedRecord shRecord = (SuanhuaRiskIdentCustomizedRecord) model;
        SuanhuaRiskIdentCustomizedData shData = shRecord.getData();

        StringBuilder sb = getBaseInfo(shRecord, successful);
        StringBuilder shSb = new StringBuilder(500);

        // retCode
        shSb.append(shData.getRetCode() == null ? "" : shData.getRetCode()).append(CRT001);
        // retMsg
        shSb.append(shData.getRetMsg() == null ? "" : shData.getRetMsg()).append(CRT001);
        // orgNum
        shSb.append(shData.getOrgNum() == null ? "" : shData.getOrgNum()).append(CRT001);
        SuanhuaRiskIdentCustomizedScore data = shData.getData();
        // data/appNum
        shSb.append(data.getAppNum() == null ? "" : data.getAppNum()).append(CRT001);
        // data/appDate
        shSb.append(data.getAppDate() == null ? "" : data.getAppDate()).append(CRT001);
        // data/appNo
        shSb.append(data.getAppNo() == null ? "" : data.getAppNo()).append(CRT001);
        // data/appStatus
        shSb.append(data.getAppStatus() == null ? "" : data.getAppStatus()).append(CRT001);
        // data/appValid
        shSb.append(data.getAppValid() == null ? "" : data.getAppValid()).append(CRT001);
        // data/errMsg
        shSb.append(data.getErrMsg() == null ? "" : data.getErrMsg()).append(CRT001);
        // data/appWarn
        shSb.append(data.getAppWarn() == null ? "" : data.getAppWarn()).append(CRT001);
        Afp7890 afp7890 = data.getAfp7890();
        // data/afp7890/dataStatus
        shSb.append(afp7890.getDataStatus() == null ? "" : afp7890.getDataStatus()).append(CRT001);
        // data/afp7890/dataValid
        shSb.append(afp7890.getDataValid() == null ? "" : afp7890.getDataValid()).append(CRT001);
        // data/afp7890/dataErrMsg
        shSb.append(afp7890.getDataErrMsg() == null ? "" : afp7890.getDataErrMsg()).append(CRT001);
        // data/afp7890/XX1000
        shSb.append(afp7890.getXx1000() == null ? "" : afp7890.getXx1000()).append(CRT001);
        // data/afp7890/XX1006
        shSb.append(afp7890.getXx1006() == null ? "" : afp7890.getXx1006()).append(CRT001);
        // data/afp7890/xx1010
        shSb.append(afp7890.getXx1010() == null ? "" : afp7890.getXx1010()).append(CRT001);
        // data/afp7890/xx1030
        shSb.append(afp7890.getXx1030() == null ? "" : afp7890.getXx1030()).append(CRT001);
        // data/afp7890/xx1031
        shSb.append(afp7890.getXx1031() == null ? "" : afp7890.getXx1031()).append(CRT001);
        // data/afp7890/XX1075
        shSb.append(afp7890.getXx1075() == null ? "" : afp7890.getXx1075()).append(CRT001);
        // data/afp7890/xx1076
        shSb.append(afp7890.getXx1076() == null ? "" : afp7890.getXx1076()).append(CRT001);
        // data/afp7890/xx1081
        shSb.append(afp7890.getXx1081() == null ? "" : afp7890.getXx1081()).append(CRT001);
        // data/afp7890/xx1107
        shSb.append(afp7890.getXx1107() == null ? "" : afp7890.getXx1107()).append(CRT001);
        // data/afp7890/xx1158
        shSb.append(afp7890.getXx1158() == null ? "" : afp7890.getXx1158()).append(CRT001);
        // data/afp7890/xx199
        shSb.append(afp7890.getXx199() == null ? "" : afp7890.getXx199()).append(CRT001);
        // data/afp7890/xx2009
        shSb.append(afp7890.getXx2009() == null ? "" : afp7890.getXx2009()).append(CRT001);
        // data/afp7890/xx2333
        shSb.append(afp7890.getXx2333() == null ? "" : afp7890.getXx2333()).append(CRT001);
        // data/afp7890/xx2486
        shSb.append(afp7890.getXx2486() == null ? "" : afp7890.getXx2486()).append(CRT001);
        // data/afp7890/xx2527
        shSb.append(afp7890.getXx2527() == null ? "" : afp7890.getXx2527()).append(CRT001);
        // data/afp7890/xx2377
        shSb.append(afp7890.getXx2377() == null ? "" : afp7890.getXx2377()).append(CRT001);
        // data/afp7890/xx2392
        shSb.append(afp7890.getXx2392() == null ? "" : afp7890.getXx2392()).append(CRT001);
        // data/afp7890/xx2419
        shSb.append(afp7890.getXx2419() == null ? "" : afp7890.getXx2419()).append(CRT001);
        // data/afp7890/xx2429
        shSb.append(afp7890.getXx2429() == null ? "" : afp7890.getXx2429()).append(CRT001);
        // data/afp7890/xx2430
        shSb.append(afp7890.getXx2430() == null ? "" : afp7890.getXx2430()).append(CRT001);
        // data/afp7890/xx2432
        shSb.append(afp7890.getXx2432() == null ? "" : afp7890.getXx2432()).append(CRT001);
        // data/afp7890/xx2443
        shSb.append(afp7890.getXx2443() == null ? "" : afp7890.getXx2443()).append(CRT001);
        // data/afp7890/xx2447
        shSb.append(afp7890.getXx2447() == null ? "" : afp7890.getXx2447()).append(CRT001);
        // data/afp7890/xx2448
        shSb.append(afp7890.getXx2448() == null ? "" : afp7890.getXx2448()).append(CRT001);
        // data/afp7890/xx310
        shSb.append(afp7890.getXx310() == null ? "" : afp7890.getXx310()).append(CRT001);
        // data/afp7890/xx312
        shSb.append(afp7890.getXx312() == null ? "" : afp7890.getXx312()).append(CRT001);
        // data/afp7890/xx313
        shSb.append(afp7890.getXx313() == null ? "" : afp7890.getXx313()).append(CRT001);
        // data/afp7890/xx320
        shSb.append(afp7890.getXx320() == null ? "" : afp7890.getXx320()).append(CRT001);
        // data/afp7890/xx324
        shSb.append(afp7890.getXx324() == null ? "" : afp7890.getXx324()).append(CRT001);
        // data/afp7890/xx361
        shSb.append(afp7890.getXx361() == null ? "" : afp7890.getXx361()).append(CRT001);
        // data/afp7890/xx367
        shSb.append(afp7890.getXx367() == null ? "" : afp7890.getXx367()).append(CRT001);
        // data/afp7890/xx371
        shSb.append(afp7890.getXx371() == null ? "" : afp7890.getXx371()).append(CRT001);
        // data/afp7890/xx395
        shSb.append(afp7890.getXx395() == null ? "" : afp7890.getXx395()).append(CRT001);
        // data/afp7890/xx401
        shSb.append(afp7890.getXx401() == null ? "" : afp7890.getXx401()).append(CRT001);
        // data/afp7890/xx458
        shSb.append(afp7890.getXx458() == null ? "" : afp7890.getXx458()).append(CRT001);
        // data/afp7890/xx461
        shSb.append(afp7890.getXx461() == null ? "" : afp7890.getXx461()).append(CRT001);
        // data/afp7890/xx514
        shSb.append(afp7890.getXx514() == null ? "" : afp7890.getXx514()).append(CRT001);
        // data/afp7890/xx518
        shSb.append(afp7890.getXx518() == null ? "" : afp7890.getXx518()).append(CRT001);
        // data/afp7890/xx542
        shSb.append(afp7890.getXx542() == null ? "" : afp7890.getXx542()).append(CRT001);
        // data/afp7890/xx548
        shSb.append(afp7890.getXx548() == null ? "" : afp7890.getXx548()).append(CRT001);
        key.set(getKey());
        val.set((sb.toString() + shSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);

        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_sh_riskident_inc";
    }

    @Override
    public String getType() {
        return RecordType.SUANHUA_RISKIDENT_CUSTOMIZED_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "算话早期风险识别-定制变量";
    }
}
